import { createParameterDecorator } from "maishu-node-mvc";
import { WeiXinDataContext, createDataContext } from "./data-context";
import { ConnectionConfig } from "mysql";
import { ServerContext } from "maishu-chitu-admin";
import { WeiXinSDK, Config } from "./weixin-sdk";

export let db: ConnectionConfig = {};

export interface Settings {
    port: number,
    gateway: string,
    db: ConnectionConfig,
}

export type ServerContentData = { db: Settings["db"] };

export let weixinDataContext = createParameterDecorator<WeiXinDataContext>(
    async (a, b, serverContext: ServerContext<ServerContentData>) => {
        let dc = await createDataContext(serverContext.data.db);
        return dc
    }
)

// export let wx = new WeiXinSDK();
export function createWeiXinSDK(config: Config) {
    let wx = new WeiXinSDK();
    Object.assign(wx.config, config);
    return wx;
}